package com.szholly.plug.safe.entity.role;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szholly.utils.util.DateUtils;
import com.szholly.data.general.IUpdateMap;
import com.szholly.data.general.UpdateMap;

@Controller
@RequestMapping("/role/*")
public class RoleCacheController {

	/**
	 * 清除缓存
	 */
	@RequestMapping(value = "/clearcache")
	@ResponseBody
	public void clearRoleCache(HttpServletRequest request,
			HttpServletResponse response) {
		RoleInitHelper.ReInitRoleData();
	}

	/**
	 * 根据主键取消角色委托功能
	 * 
	 * @param request
	 * @param response
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/enable")
	@ResponseBody
	public void enableRoleWt(HttpServletRequest request,
			HttpServletResponse response) {
		String rowString = request.getParameter("rowKey");
		// 数据对象
		JSONObject queryJsonObject = JSONObject.fromObject(rowString);
		HashMap<String, Object> whereMap = (HashMap<String, Object>) JSONObject
				.toBean(queryJsonObject, HashMap.class);
		
		IUpdateMap updateMap = new UpdateMap();
		updateMap.setWhereMap(whereMap);
		HashMap<String, Object> setMap = new HashMap<String, Object>();
		setMap.put(RoleChangeEntity.FIELD_ISUSE, RoleWtDic.cancel);
		setMap.put(RoleChangeEntity.FIELD_DJ_ENDTIME, DateUtils.convertDateTimeToString(null));
		updateMap.setSetMap(setMap);
		
		RoleChangeService.getSingleRef().update(updateMap);
	}
}